//import "@stdlib/ownable";
//import "@stdlib/deploy";
//
//// 本合约中的Leai为席位
//message InintLeai {
//    superior: Address;
//}
//
//message NewLeaiResponse {
//    num: Int as uint256;
//}
//
//message AddLeaiNum {
//    num: Int as uint256;
//}
//
//message SendMesg {
//    superior: Address;
//    jettonAddress: Address;
//}
//
//message RewardLeai {
//    amount: Int as uint256;
//}
//
//message Withdrawal {
//    amount: Int as uint256;
//}
//
//message JettonAddress {
//    ad: Address;
//}
//
//
//message(0xf8a7ea5) TokenTransfer {
//    queryId: Int as uint64;
//    amount: Int as coins;
//    destination: Address;
//    response_destination: Address;
//    custom_payload: Cell?;
//    forward_ton_amount: Int as coins;
//    forward_payload: Slice as remaining; // Comment Text message when Transfer the jetton
//}
//
//message(0x178d4519) TokenTransferInternal {
//    queryId: Int as uint64;
//    amount: Int as coins;
//    from: Address;
//    response_destination: Address;
//    forward_ton_amount: Int as coins;
//    forward_payload: Slice as remaining; // Comment Text message when Transfer the jetton
//}
//
//
//contract LeAIParent with Deployable,Ownable {
//
//    const MinTonForStorage: Int = ton("0.5"); // enough for 1 KB of storage for 2.5 years
//
//    owner: Address;
//    own: Address; // 最高权限
//    dev: Address; // 开发者权限
//    numLeai:Int as uint256 = 0;
//    maxnumLeai:Int as uint256 = 100; // 最多创建100个
//    jettonAddress:Address;
//
//
//    init(dev:Address,jettonAddress:Address) {
//        self.own = sender();
//        self.owner = sender();
//        self.dev = dev;
//        self.jettonAddress = jettonAddress;
//    }
//
//    // 用户创建一个 leai
//    receive(msg: InintLeai) {
//        self.numLeai = self.numLeai + 1;
//        require(myBalance() <= self.MinTonForStorage, "Insufficient contract balance ton");
//        require(self.numLeai < self.maxnumLeai, "No extra Leai !");
//        // 创建新的LeAai todo
//        let init: StateInit = initOf LeAIChild(myAddress(), sender());
//        // 给新创建的LeAai 发送消息
//        send(SendParameters{
//        to: contractAddress(init),
//        body: SendMesg{ superior: msg.superior,jettonAddress:self.jettonAddress}.toCell(),
//        value: ton("0.1"),
//        mode: SendBounceIfActionFail,
//        code: init.code,
//        data: init.data
//        });
//        self.reply(NewLeaiResponse{ num:self.numLeai }.toCell()); // 剩余 gas 返回给 发送者 ,并传递当前的数量
//    }
//
//    // 给用户发送激励代币 todo
//    receive(msg: RewardLeai) {
//        require(self.dev == sender() || self.own == sender(), "You are not dev or own!");
//        let winit: StateInit = initOf LeAIChild(myAddress(), sender());
//        // 给给用户的合约地址转移
//        send(SendParameters{
//        to: self.jettonAddress,
//        body: self.tokenTransferInternal(msg.amount,contractAddress(winit),myAddress()).toCell(),
//        value: ton("0.1"),
//        mode: SendBounceIfActionFail
//        });
//        //通知用户发放奖励
//        send(SendParameters{
//        to: contractAddress(winit),
//        body: RewardLeai{amount:msg.amount}.toCell(),
//        value: ton("0.1"),
//        mode: SendBounceIfActionFail,
//        code: winit.code,
//        data: winit.data
//        });
//        self.reply("start rewardLeai".asComment());
//    }
//
//    // 增发 Leai
//    receive(msg: AddLeaiNum) {
//        require(sender() == self.own, "not own !");
//        self.maxnumLeai = self.maxnumLeai + msg.num;
//        self.reply(NewLeaiResponse{
//        num:self.numLeai}.toCell()); // 剩余 gas 返回给 发送者 ,并传递当前的数量
//    }
//
//    // 设置代币地址
//    receive(msg: JettonAddress) {
//        require(sender() == self.own, "not own !");
//        self.jettonAddress = msg.ad;
//        self.reply("set jetton address".asComment()); // 剩余 gas 返回给 发送者 ,并传递当前的数量
//    }
//
//    fun tokenTransferInternal(amount:Int,to:Address,from:Address): TokenTransferInternal{
//        return
//        TokenTransferInternal{
//        queryId: 0,
//        amount: amount,
//        from: from,
//        response_destination: to,
//        forward_ton_amount: 0,
//        forward_payload: emptySlice()
//        }
//    }
//    // 获取主合约的地址
//    get fun getParentContractAddress(): Address {
//        return myAddress();
//    }
//
//    // 获取子合约的数量
//    get fun getLeAaiNum(): Int {
//        return self.numLeai;
//    }
//    // 获取自己的合约
//    get fun getLeAaiAddress(ad: Address): Address {
//        return contractAddress(initOf LeAIChild(myAddress(), ad));
//    }
//
//    get fun getJettonAddress(): Address {
//        return self.jettonAddress;
//    }
//
//}
//
//struct LeAIDetails {
//    address: Address;
//    balance: Int as uint256;
//    superior: Address;
//    parent: Address;
//}
//
//contract LeAIChild with Deployable{
//
//    parent: Address;
//    index: Int as uint256;
//    balance: Int as uint256;
//    superior: Address;
//    own:Address;
//    proportion:Int as uint256;
//    jettonAddress:Address;
//
//    init(parent: Address, sender: Address) {
//        self.parent = parent;
//        self.balance = 0;
//        self.own = sender;
//        self.proportion = 5;
//        self.superior = newAddress(0,0);
//        self.index = 0;
//        self.jettonAddress = newAddress(0,0);
//    }
//
//    receive(msg: SendMesg) {
//        require(sender() == self.parent, "Parent only");
//        self.superior = msg.superior;
//        self.jettonAddress = msg.jettonAddress;
//    }
//
//    // 基于上级百分之5的激励
//    receive(msg: RewardLeai) {
//        require(sender() == self.parent, "Parent only");
//        require(msg.amount <= 0, "zero,end!");
//        self.balance = self.balance + msg.amount;
//        // 上级合约地址
//        let winit: StateInit = initOf LeAIChild(self.parent, self.superior);
//        // 给给用户的合约地址转移
//        send(SendParameters{
//        to: self.jettonAddress,
//        body: self.tokenTransferInternal(msg.amount,contractAddress(winit),myAddress()).toCell(),
//        value: ton("0.1"),
//        mode: SendBounceIfActionFail
//        });
//        //继续通知用户发放奖励
//        let amount : Int = msg.amount * self.proportion / 100 ;
//        send(SendParameters{
//        to: contractAddress(winit),
//        body: RewardLeai{amount:amount}.toCell(),
//        value: ton("0.1"),
//        mode: SendBounceIfActionFail,
//        code: winit.code,
//        data: winit.data
//        });
//        self.reply("Received and continue".asComment()); // 剩余 gas 返回给 发送者 ,并传递当前的数量
//    }
//
//    // 提现 todo
//    receive(msg: Withdrawal) {
//        require(self.own == sender(), "Insufficient permissions");
//        require(msg.amount <= self.balance, "zero,end!");
//        self.balance = self.balance - msg.amount;
//        // 把代币转移到用户的地址上
//        send(SendParameters{
//        to: self.jettonAddress,
//        body: self.tokenTransferInternal(msg.amount,self.own,myAddress()).toCell(),
//        value: ton("0.1"),
//        mode: SendBounceIfActionFail
//        });
//        self.reply("withdrawal".asComment()); // 剩余 gas 返回给 发送者 ,并传递当前的数量
//    }
//
//    fun tokenTransferInternal(amount:Int,to:Address,from:Address): TokenTransferInternal{
//        return
//        TokenTransferInternal{
//        queryId: 0,
//        amount: amount,
//        from: from,
//        response_destination: to,
//        forward_ton_amount: 0,
//        forward_payload: emptySlice()
//        }
//    }
//
//    // 合约地址 合约余额 上级 父级
//    get fun details(): LeAIDetails{
//        return LeAIDetails{
//        address:myAddress(),
//        balance:self.balance,
//        superior:self.superior,
//        parent:self.parent
//        };
//    }
//}